/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.net.URL;
import java.util.ArrayList;
import java.util.TreeMap;

/**
 *
 * @author fabio
 */
public class Content {

    private Mail mail;
    private int CapsLong;
    private int CapsAvg;
    private int CapsTotal;
    private int ImgCounter;
    private int WordCounter;
    private int LineCounter;
    private int LinkCounter;
    private int CharactersSpacesHtml;
    private int CharactersNoSpacesHtml;
    private int CharactersSpacesNoHtml;
    private int CharactersNoSpacesNoHtml;
    private TreeMap<String, Word> words;
    private TreeMap<String, Link> links;
    private ArrayList<Word> wordsOrder;

    public Content(Mail mail) {
        this.mail = mail;
        this.wordsOrder = new ArrayList<Word>();
        this.words = new TreeMap<String, Word>();
        this.links = new TreeMap<String, Link>();
    }

    public void insertWord(String word) {
        Word wordW;
        if (words.containsKey(word)) {
            wordW = words.get(word);
            wordW.incrementCounter();
        } else {
            wordW = new Word(word);
            wordW.incrementCounter();
            words.put(word, wordW);
        }
        wordsOrder.add(wordW);
    }

    public void updateContent(int CapsLong, int CapsAvg, int CapsTotal, int ImgCounter, int WordCounter, int LineCounter, int CharactersSpacesHtml, int CharactersNoSpacesHtml, int CharactersSpacesNoHtml, int CharactersNoSpacesNoHtml, ArrayList<URL> links) {
        this.CapsLong = CapsLong;
        this.CapsAvg = CapsAvg;
        this.CapsTotal = CapsTotal;
        this.ImgCounter = ImgCounter;
        this.WordCounter = WordCounter;
        this.LineCounter = LineCounter;
        this.CharactersSpacesHtml = CharactersSpacesHtml;
        this.CharactersNoSpacesHtml = CharactersNoSpacesHtml;
        this.CharactersSpacesNoHtml = CharactersSpacesNoHtml;
        this.CharactersNoSpacesNoHtml = CharactersNoSpacesNoHtml;
        this.LinkCounter = links.size();
        this.insertLinks(links);
    }

    public void insertLinks(ArrayList<URL> linksArray) {
        for (URL url : linksArray) {
            String linkDomain = url.getHost();
            Link link;
            if (links.containsKey(linkDomain)) {
                link = links.get(linkDomain);
                if (mail.getSpam() == 1) {
                    link.incrementBad();
                } else if (mail.getSpam() == 0) {
                    link.incrementGood();
                }
            } else {
                link = new Link(linkDomain);
                if (mail.getSpam() == 1) {
                    link.incrementBad();
                } else if (mail.getSpam() == 0) {
                    link.incrementGood();
                }
                links.put(linkDomain, link);
            }
        }
    }

    public int getCapsAvg() {
        return CapsAvg;
    }

    public int getCapsLong() {
        return CapsLong;
    }

    public int getCapsTotal() {
        return CapsTotal;
    }

    public int getCharactersNoSpacesHtml() {
        return CharactersNoSpacesHtml;
    }

    public int getCharactersNoSpacesNoHtml() {
        return CharactersNoSpacesNoHtml;
    }

    public int getCharactersSpacesHtml() {
        return CharactersSpacesHtml;
    }

    public int getCharactersSpacesNoHtml() {
        return CharactersSpacesNoHtml;
    }

    public int getImgCounter() {
        return ImgCounter;
    }

    public int getLineCounter() {
        return LineCounter;
    }

    public int getLinkCounter() {
        return LinkCounter;
    }

    public int getWordCounter() {
        return WordCounter;
    }

    public TreeMap<String, Link> getLinks() {
        return links;
    }

    public Mail getMail() {
        return mail;
    }

    public TreeMap<String, Word> getWords() {
        return words;
    }

    public ArrayList<Word> getWordArrayList() {
        return wordsOrder;
    }

    @Override
    public String toString() {
        return "Content{" + "mail=" + mail + ", CapsLong=" + CapsLong + ", CapsAvg=" + CapsAvg + ", CapsTotal=" + CapsTotal + ", ImgCounter=" + ImgCounter + ", WordCounter=" + WordCounter + ", LineCounter=" + LineCounter + ", LinkCounter=" + LinkCounter + ", CharactersSpacesHtml=" + CharactersSpacesHtml + ", CharactersNoSpacesHtml=" + CharactersNoSpacesHtml + ", CharactersSpacesNoHtml=" + CharactersSpacesNoHtml + ", CharactersNoSpacesNoHtml=" + CharactersNoSpacesNoHtml + ", words=" + words + ", links=" + links + ", wordsOrder=" + wordsOrder + '}';
    }
}
